xquery version "1.0-ml";

import module namespace ox="http://localhost/ns/ox" at "/porvino/lib/ox/ox.xqy";
import module namespace plib = "http://porvino.com/lib" at "/porvino/lib/lib.xqy";
import module namespace tags = "http://www.porvino.com/tags" at "/porvino/tags/tags.xqy";
import module namespace text = "http://www.porvino.com/text-input" at "/porvino/text-input/text-input.xqy";

let $g_id := xdmp:get-request-field("id")
(:let $host := fn:concat("http://",xdmp:host-name(),":8000/porvino") :)
let $host := fn:concat("/porvino")

return
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>edit wine</title>
		<script>var g_id = {$g_id};</script>
		<script type="text/javascript" src="/porvino/lib/ox/ox.js"></script>
		<script type="text/javascript" src="/porvino/lib/ox/oxutil_1_0.js"></script>
		<script type="text/javascript" src="/porvino/lib/wine.js"></script>
		<script type="text/javascript" src="/porvino/tags/tags.js"></script>
		<script type="text/javascript" src="/porvino/text-input/text-input.js"></script>
<!--		<script type="text/javascript" src="/lib/dojo/dojo-0.4.0-ajax/dojo.js"></script>
		<script type="text/javascript">dojo.require("dojo.widget.Select");</script>
		<script type="text/javascript">dojo.require("dojo.widget.Editor");</script>   -->
<!--		<script type="text/javascript" src="/porvino/lib/scriptac/prototype.js"></script>
		<script type="text/javascript" src="/porvino/lib/scriptac/scriptaculous.js"></script>
		<script type="text/javascript" src="/porvino/lib/scriptac/controls.js"></script>
		<script type="text/javascript" src="/porvino/lib/scriptac/dragdrop.js"></script>
		<script type="text/javascript" src="/porvino/lib/scriptac/effects.js"></script> -->
		<link rel="stylesheet" href="/porvino/style/home.css" type="text/css"></link>
	
		
	</head>

	<body>

		{plib:globalNav()}

		<script>
			<![CDATA[updateAttribute("doc(\'" + g_id + "\')/wine", g_id,   "", "dateViewed" , "currentdatetime")]]>
		</script>
		<form action="" name="editform">


<!-- first table containing the primary facts, holds widgets -->
<table id="widgettable" width="100%" border="0" cellspacing="0"> <!-- begin widget holding table -->
    <tr border="0">
        <td id="col1" width="50%" valign="top"> <!-- the first of two widget columns -->
            <script>
            <![CDATA[ makeDroppable(document.getElementById("col1")); //make this a source or target for draggable objects]]>
            </script>
    		<div class="widgetInput" id="widgetBasics" onmousedown="" onmouseover=""> <!-- begin widget: basics -->
    			<script>
    				<![CDATA[makeDraggable(document.getElementById("widgetBasics")); //make this draggable]]>	
    			</script>
    			<div class="widgetHeaderInput" id="widgetHeaderBasics">
    				<table class="widgetHeaderInput">
    					<tr>
    					<td class="widgetHeaderInput" >Basics</td>
    					</tr>
    				</table>
    			</div>
    			<div class="widgetBodyInput" id="widgetBodyBasics"> <!-- begin widget body: basics -->
    
    				<table class="tableInput" border="0" cellspacing="0"> <!-- begin vintage, winery table -->
    					<tr>
    						<td bgcolor="CCCCCC">
    						  vintage<br/>
    						  {text:get-text-input-controls("vineyard", $host, $g_id, "/wine/vintage", "width:40px;")}
    						</td>
    
                            <td bgcolor="CCCCCC">
                            	winery<br/>
                            	{text:get-text-input-controls("vineyard", $host, $g_id, "/wine/winery", "width:155px;")}
                            </td>
    
                            <td bgcolor="CCCCCC">		
                            	name<br/>
                            	{text:get-text-input-controls("vineyard", $host, $g_id, "/wine/name", "width:200px;")}
                            </td>
                        </tr>
        
                        <tr>
                            <td colspan="1"  bgcolor="CCCCCC">  
                                region<br/>
                                {text:get-text-input-controls("region", $host, $g_id, "/wine/region", "width: 120px;")}
                            </td>
                            <td colspan="1"  bgcolor="CCCCCC">	
                            	appellation<br/>
                            	{text:get-text-input-controls("appellation", $host, $g_id, "/wine/appellation", "width: 200px;")}
                            </td>
                            <td  bgcolor="CCCCCC">
                            	vineyard<br/>
                            	{text:get-text-input-controls("vineyard", $host, $g_id, "/wine/vineyard", "width: 200px;")}
                            </td>
                        </tr>
                        
                        <tr>
                            <td colspan="2"  bgcolor="CCCCCC">
                            	primary varietal<br/>
                            	{text:get-text-input-controls("vineyard", $host, $g_id, "/wine/varietal", "width: 200px;")}
                            </td>
                            <td colspan="2" bgcolor="CCCCCC"  style="padding:0;">
                                <table border="0" cellspacing="0" style="padding:0;width:100%;">
                                    <tr>
                                       <td style="padding:2;">
                                           maturity start<br/>
                                            {text:get-text-input-controls("vineyard", $host, $g_id, "/wine/start", "width:80px;")}
                                        </td>
                                        <td bgcolor="CCCCCC" style="padding:2;width:30%;">
                                            maturity end<br/>
                                            {text:get-text-input-controls("vineyard", $host, $g_id, "/wine/end", "width:80px;")}
                                        </td>
                                     </tr>
                                </table>
                            </td>
                        </tr>

                        <tr>
                            
                        </tr>
        
                    </table> <!-- end vintage table -->
 
    </div> <!-- end widget body: basics -->
</div> <!-- end widget: basics -->


<div class="widgetInput" id="widgetBlend" onmousedown="" onmouseover=""> <!-- begin widget: details -->
    <script>
    <![CDATA[makeDraggable(document.getElementById("widgetBlend"));//make this draggable]]>	
    </script>
    <div class="widgetHeaderInput" id="widgetHeaderBlend"> 
    	<table class="widgetHeaderInput">
    		<tr>
    			<td class="widgetHeaderInput">Details</td>
    			<td class="widgetHeaderInput" align="right">
                    <a class="nav" id="addVarietal" name="addVarietal" value="Add Varietal" onClick="newBlendField(document);">+ Varietal Blend</a>
                </td>
    		</tr>
    	</table>
    </div>
    <div class="widgetBodyInput" id="widgetBodyBlend"> <!-- begin widget body: details -->
        <table border="0" cellspacing="0">
            <tr>
            	<td bgcolor="CCCCCC">
            		varietal
            	</td>
            	<td bgcolor="CCCCCC" >
            		percentage
            	</td>
            	<td bgcolor="CCCCCC" >
                    &nbsp;
                </td>
            </tr>

            <tr>
                <div id="blend"></div>
                <td bgcolor="CCCCCC"  id="vcol"></td>
                <td bgcolor="CCCCCC"  id="bpcol"></td>
                <td bgcolor="CCCCCC"  id="delcol"></td>
            </tr>
            <script language = "javascript">
            <![CDATA[showBlendFields(document);]]>
            </script>
            
            <!--
            //group needs to handle the repeat aspect. it needs knowledge of the container
            //also needs to support relationships between components passed in such as the delete button for a row
            // first simplify so that the repeat logic is at this layer
            -->
            {text:get-input-group(
                "varietal-input",
                $g_id,
                "/wine/blend/blendPart",
                <components xmlns="http://www.porvino.com/text-input">
                    <component>
                        <label>varietal</label>
                        <function>text:get-text-input-controls</function>
                        <component-id>blendvarietal</component-id>
                        <host>{$host}</host>
                        <doc-id>{$g_id}</doc-id>
                        <data-node-leaf>blendVarietal</data-node-leaf>
                        <style>width:230px;</style>
                    </component>
                    <component>
                        <label>percentage</label>
                        <function>text:get-text-input-controls</function>
                        <component-id>blendpercentage</component-id>
                        <host>{$host}</host>
                        <doc-id>{$g_id}</doc-id>
                        <data-node-leaf>blendPercentage</data-node-leaf>
                        <style>width:60px;</style>
                    </component>
                    <component>
                        <label></label>
                        <function>text:get-delete-group-row</function>
                        <component-id>delete-group-row</component-id>
                        <host>{$host}</host>
                        <doc-id>{$g_id}</doc-id>
                        <data-node-leaf></data-node-leaf>
                        <style>height:16px;width:16px;</style>
                        <image>/porvino/images/cancel_off.png</image>
                    </component>
                </components>
             )}
            

            
            <tr>
                <td colspan="3">
                    <div style="float:left">
                        alcohol<br/>
                        {text:get-text-input-controls("vineyard", $host, $g_id, "/wine/alcohol", "width:40px;")}
                    </div>
                    
                    <div style="float:left">
                        sugar<br/>
                        {text:get-text-input-controls("vineyard", $host, $g_id, "/wine/sugar", "width:40px;")}
                    </div>
                    
                    <div style="float:left">
                        ph<br/>
                        {text:get-text-input-controls("vineyard", $host, $g_id, "/wine/ph", "width:40px;")}
                    </div>
                </td>
            </tr>
            
        </table>
        
    </div> <!-- end widget details body div -->
</div> <!-- end widget detail div -->


<div class="widgetInput" id="widgetInv" onmousedown="" onmouseover="">
    <script>
    <![CDATA[makeDraggable(document.getElementById("widgetInv"));]]>	
    </script>
    <div class="widgetHeaderInput" id="widgetHeaderInv">
    	<table class="widgetHeaderInput">
    		<tr>
    			<td class="widgetHeaderInput" >Inventory</td>
    			<td class="widgetHeaderInput" align="right"><a class="nav" id="addInventory" name="addInventory" value="Add Inventory" onClick="newInventoryField(document);">+ Inventory</a></td>
    		</tr>
    	</table>
    </div>
    <div class="widgetBodyInput" id="widgetBodyInv">
    	<table border="0" cellspacing="0">
	       <tr>
                <td colspan="3" id="bottleDisplay">
                    <script>
                        <![CDATA[getOnHand('doc(\'' + g_id + '\')/wine',g_id, 'inventory/inventoryEntry/onhand',function (e) {var cases = Math.floor(e/12);var bottles = e % 12;addHtml(document.getElementById("bottleDisplay"),"cases:"+cases+"  bottles:"+bottles, e);} )]]> 
                    </script>
                </td>
            </tr>
    		<tr>
    			<td colspan="2" bgcolor="CCCCCC" style="padding:0;">
                    <table border="0" cellspacing="0">
                    	<tr>
                            <td bgcolor="CCCCCC">
                                avail
                            </td>
                            <td bgcolor="CCCCCC" >
                                qty
                            </td>
                            <td bgcolor="CCCCCC" >
                                location
                            </td>
                            <td bgcolor="CCCCCC" >
                                size
                            </td>
                            <td bgcolor="CCCCCC" >
                                cost
                            </td>
                            <td bgcolor="CCCCCC" >
                                date
                            </td>
                            <td bgcolor="CCCCCC" >
                                future
                            </td>
                            <td bgcolor="CCCCCC" >
                                wish
                            </td>
                            <td bgcolor="CCCCCC" >
                                
                            </td>
                        </tr>
            
                        <tr>
                            <div id="inventory"></div>
                            <td bgcolor="CCCCCC"  id="onhandcol"></td>
                            <td bgcolor="CCCCCC"  id="qtycol"></td>
                            <td bgcolor="CCCCCC"  id="locationcol"></td>
                            <td bgcolor="CCCCCC"  id="sizecol"></td>
                            <td bgcolor="CCCCCC"  id="costcol"></td>
                            <td bgcolor="CCCCCC"  id="datecol"></td>
                            <td bgcolor="CCCCCC"  id="futurecol"></td>
                            <td bgcolor="CCCCCC"  id="wishcol"></td>
                            <td bgcolor="CCCCCC"  id="invdelcol"></td>
                        </tr>
                        <script language = "javascript">
                        <![CDATA[showInventoryFields(document);]]>
                        </script>

                    </table>
                </td>
            </tr>
        </table>
    </div> <!-- body div -->
</div> <!-- widget div -->

</td> <!-- end of the first column that holds widgets on this page -->


<td id="col2" width="50%" valign="top"> <!-- start of the second column that holds widgets onthis page -->
	<script>
	<![CDATA[makeDroppable(document.getElementById("col2"));]]>
	</script>

<div class="widgetInput" id="widgetGen" onmousedown="" onmouseover="">
					<script>
					<![CDATA[makeDraggable(document.getElementById("widgetGen"));]]>	
					</script>
<div class="widgetHeaderInput" id="widgetHeaderGen">
	<table class="widgetHeaderInput">
		<tr>
			<td class="widgetHeaderInput" >General Notes</td>
		</tr>
	</table>
</div>
<div class="widgetBodyInput" id="widgetBodyGen">


<table border="0" width="100%">

<tr>

<td colspan="3">
	<textarea cols="40" rows="5" name="generalNotes" id="generalNotes"
	onChange="updateElementText('doc(\'' + g_id + '\')/wine', g_id, 'generalNotes', encodeURI(escape(this.value)));"
	/>
	<script>
		<![CDATA[getValue('doc(\'' + g_id + '\')/wine',g_id, 'generalNotes', function (e) {document.getElementById("generalNotes").value=unescape(e);})]]>	
	</script>

</td>
</tr>
</table>
</div> <!-- body div -->
</div> <!-- widget div -->



<div class="widgetInput" id="widgetNotes" onmousedown="" onmouseover="">
	<script>
	<![CDATA[makeDraggable(document.getElementById("widgetNotes"));]]>	
	</script>
<div class="widgetHeaderInput" id="widgetHeaderNotes">
	<table class="widgetHeaderInput" border="0">
		<tr>
			<td class="widgetHeaderInput" align="left">Tasting Notes</td>
			<td class="widgetHeaderInput" align="right"><a class="nav" id="addTastingNote" name="addTastingNote" value="Add Tasting Note" onClick="newTastingField(document);">+ Tasting Note</a></td>
		</tr>
	</table>
</div>
<div class="widgetBodyInput" id="widgetBodyNotes">

<table  cellspacing="0" name="tastingNotes" id="tastingNotes" width="100%" border="0">
<tr> </tr>
<script language = "javascript">
	<![CDATA[showTastingFields(document);]]>
</script>
</table>


</div> <!-- body div -->
</div> <!-- widget div -->


<div class="widgetInput" id="widgetTags" onmousedown="" onmouseover=""> <!-- begin widget: tags -->
                <script>
                    <![CDATA[makeDraggable(document.getElementById("widgetBasics")); //make this draggable]]>   
                </script>
                <div class="widgetHeaderInput" id="widgetHeaderTags">
                    <table class="widgetHeaderInput">
                        <tr>
                        <td class="widgetHeaderInput" >Tags</td>
                        </tr>
                    </table>
                </div>
                <div class="widgetBodyInput" id="widgetBodyTags"> <!-- begin widget body: tags -->
    
                    <table class="tableInput" border="0" cellspacing="0"> <!-- begin vintage, winery table -->                        
                        <tr>
                            <td>
                                {tags:get-tag-controls("1", $host, $g_id, "/wine")}
                            </td>
                       </tr>
                    </table> <!-- end vtable -->
 
    </div> <!-- end widget body: tags -->
</div> <!-- end widget: tags -->



</td></tr>


</table>

			
			<br/>curr time: {fn:current-dateTime()}
		</form>

	</body>
</html>